package com.yunsoft.jdbc;

import java.util.Properties;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.stereotype.Component;

public class SessionFactoryBean {

	public LocalSessionFactoryBean sessionFactory(DataSource dataSource){
		LocalSessionFactoryBean sfb = new LocalSessionFactoryBean();
		sfb.setDataSource(dataSource);
//		sfb.setMappingResources(new String[]{"Spitter.xml"});
		sfb.setPackagesToScan(new String[]{"com.yunsoft.pojo"});
		Properties prpos = new Properties();
		prpos.setProperty("dialect", "org.hibernate.dialect.MysqlDialect");
		prpos.setProperty("show_sql", "true");
		prpos.setProperty("hibernate.hbm2ddl.auto", "update");
		prpos.setProperty("format_sql", "true");
		prpos.setProperty("hibernate.current_session_context_class", "true");
		sfb.setHibernateProperties(prpos);
		return sfb;
	}
	
	//会在repository注解
	@Bean
	public BeanPostProcessor persistenceTranslation(){
		return new PersistenceExceptionTranslationPostProcessor();
	}
}
